<template>
  <div class="GCooperativeSiteReportDetail">
    <filterPanel filterName="GCooperativeSiteReportDetailFilter" filterTitle="合作物流企业列表查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="GCooperativeSiteReportDetailTable" :tableLoading="loading" tableTitle="合作物流企业列表"
                :tableList="tableList" :tableData="tableData" :total="total" :currentPage="form.page_start"
                :pageSize="form.page_size" @sizeChange="sizeChange" @pageChange="pageChange">
      <div class="total-box">
        <div class="total-info">寄件合计<span>（{{rec_count}}）</span>件</div>
        <div class="total-info">收件合计<span>（{{send_count}}）</span>件</div>
        <div class="total-info">总计<span>（{{ttnum}}）</span>件</div>
      </div>
      <zy-button type="primary" @click="exportExcel">导出列表</zy-button>
    </tablePanel>
  </div>
</template>

<script>
	export default {
		name: "GCooperativeSiteReportDetail",
		props: {},
		data() {
			return {
				currentPath: '/cooperative_site_report_detail',
				filterData: [
					{
						title: '企业编号',
						name: 'company_sn',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业名称',
						name: 'company_name',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业类型',
						name: 'company_type',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '物流', value: 0},
							{label: '快递', value: 1},
							{label: '分拣中心', value: 2},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '统一社会信用代码',
						name: 'organization_code',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人姓名',
						name: 'legal_person',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人联系方式',
						name: 'legal_phone',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '收寄件时间',
						name: 'registration_date',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
				],
				form: {
					company_sn: '',
					company_name: '',
					company_type: '',
					organization_code: '',
					legal_person: '',
					legal_phone: '',
					registration_date: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '企业编号',
						width: 200,
						name: 'company_sn',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业名称',
						width: 200,
						name: 'company_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业类型',
						width: 100,
						name: 'company_type',
						isShow: true,
						isSelected: true
					},
					{
						title: '统一社会信用代码',
						width: 200,
						name: 'organization_code',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人姓名',
						width: 120,
						name: 'legal_person',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人联系方式',
						width: 160,
						name: 'legal_phone',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件数量',
						width: 160,
						name: 'send_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件数量',
						width: 160,
						name: 'rec_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计',
						width: 160,
						name: 'num',
						isShow: true,
						isSelected: true
					},
				],
				tableData: [],
				total: 0,
				download_url: '',
				cooper_id: '',
				rec_count: 0,
				send_count: 0,
				ttnum: 0
			};
		},
		computed: {
			postData() {
				let data = {
					cooper_id: this.cooper_id,
					company_sn: this.form.company_sn,
					company_name: this.form.company_name,
					company_type: this.form.company_type,
					organization_code: this.form.organization_code,
					legal_person: this.form.legal_person,
					legal_phone: this.form.legal_phone,
					group_method: 0,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.registration_date && this.form.registration_date.length > 0) {
					data.start_created_time = this.form.registration_date[0] / 1000;
					data.end_created_time = this.form.registration_date[1] / 1000;
				}
				return data;
			},
		},
		watch: {},
		components: {},
		methods: {
			//导出
			exportExcel() {
				this.$import_excal(this.download_url || "");
			},
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.tableData = [];
				this.$axios.post(this.$api.g_logisticsReport, {...this.postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.tableData = data.list.filter(item => {
							return item;
						});
						this.rec_count = data.rec_count || 0;
						this.send_count = data.send_count || 0;
						this.ttnum = data.ttnum || 0;
						this.download_url = data.download_url || ''
						this.total = data.pagination.total_count || 0;
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.loading = false;
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
		},
		mounted() {
			this.cooper_id = this.$route.query.cooper_id || ''
			this.getData();
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/reportManage/cooperativeSiteDetail/index.less">

</style>
